<?php
    /* Fingon 2011.07 */
    require_once('global.php');
    require_once('/code/Include/db_mysql.php');
    require_once('/code/Include/thumb_handler.php');
    
    Class SiteInfo
    {
        protected $db;
        
        public $HOMEPAGE_IMG_URL='/styles/images/homepage-photo.jpg';
        public $ABOUT_IMG_URL='/styles/images/about.jpg';
        
        public function SiteInfo(){
            $this->db=new DB();
        }
    
        public function getSiteInfo(){
            $sql='select site_info.*, artist.name, product.subject as frontpage_product_subject from `site_info` left join `artist` on site_info.frontpage_artist_id=artist.artist_id left join `product` on site_info.frontpage_product_id=product.product_id where site_info.id=1';
            return $this->db->get_one($sql);
        }
        
        public function editSiteInfo($s){
            $s=$this->db->prepare_param($s);
            $sql=sprintf("update `site_info` set `site_name`='%s', `meta_keyword`='%s', `meta_description`='%s', `site_about`='%s', `contact_email`='%s', `address`='%s', `terms_condition`='%s', `frontpage_artist_id`=%s, `frontpage_product_id`=%s, `watermark_text`='%s', `watermark_transparency`=%s, `watermark_fontsize_img`=%s, `watermark_fontsize_thumb`=%s where id=1", $s['site_name'], $s['meta_keyword'], $s['meta_description'], $s['site_about'], $s['contact_email'], $s['address'], $s['terms_condition'], $s['frontpage_artist_id'], $s['frontpage_product_id'], $s['watermark_text'], $s['watermark_transparency'], $s['watermark_fontsize_img'], $s['watermark_fontsize_thumb']);
            return $this->db->update($sql); 
        }
        
        public function getWartermark(){
            $sql='select watermark_text, watermark_transparency, watermark_fontsize_img, watermark_fontsize_thumb from `site_info` where id=1';
            return $this->db->get_one($sql);
        }
        
        public function getContact(){
            $sql='select site_name, contact_email, address from `site_info` where id=1';
            return $this->db->get_one($sql);
        }
        
        public function text2Html($t, $nl2br=0){
            $t=str_replace('  ', '&nbsp;&nbsp;', $t);
            if($nl2br) $t=nl2br($t);
            return $t;
        }
        
        public function uploadImg($img_url, $filename){
            return move_uploaded_file($filename, $img_url);
        }
        
        public function getFooterContent($site_name){
            echo '<ul><li>&copy; '.$site_name.' All rights reserved.</li><li><a href="/about/terms-conditions">Terms & Conditions</a></li><li>|</li><li><a href="/about">About us</a></li><li>|</li><li><a href="/contact">Contact us</a></li><ul>';
        }
    }
    
?> 